// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  // API 调用都保持和云函数当前所在环境一致
  env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
  let{ username, password, userType, gender} = event
  let openid = event.userInfo.openid
  let{ appId, openId} = event.userInfo
  // console.log('openid'+OPENID)
  console.log('openidinfo'+openId)
  console.log(JSON.stringify(event))
  await db.collection('user').add({
    data: {
      _openid: openId,
      username: username,
      password: password,
      gender: gender,
      userType: userType
    },
    success: res=>{
      console.log('add success')
    }
  })
  return 
}